/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.metaaps.eoraster;

import java.awt.image.RenderedImage;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;

import com.sun.media.imageio.plugins.tiff.TIFFDirectory;
import com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader;
import com.sun.media.imageioimpl.plugins.tiff.TIFFImageReaderSpi;


/**
 * This is a convenience class that warp a tiff image to easily use in the case
 * of one geotiff per band (like radarsat 2 images)
 * @author thoorfr
 */
public class TIFF {


    public TIFFImageReader reader;
    public TIFFDirectory td;
    public RenderedImage image=null;

    public TIFF(File imageFile) {
        try {
            reader = new TIFFImageReader(new TIFFImageReaderSpi());
            ImageInputStream iis = ImageIO.createImageInputStream(imageFile);
            reader.setInput(iis);
            td = TIFFDirectory.createFromMetadata(reader.getImageMetadata(0));
        } catch (Exception ex) {
            Logger.getLogger(TIFF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void dispose(){
        try {
            image = null;
            td=null;
            reader.dispose();
        } catch (Exception ex) {
            Logger.getLogger(TIFF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
